package me.stone.stanimeclient.core.ui.player

import android.media.AudioManager
import android.media.audiofx.LoudnessEnhancer

class VolumeManager(private val audioManager: AudioManager) {

    private val currentStreamVolume: Int
        get() = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)

    var currentVolume = currentStreamVolume.toFloat()
        private set

    val maxVolume: Int
        get() = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)

    val volumePercentage: Int
        get() = (currentVolume / maxVolume.toFloat()).times(100).toInt()

    fun setVolume(volume: Float) {
        currentVolume = volume.coerceIn(0f, maxVolume.toFloat())
        audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume.toInt(),0,)
    }

    fun increaseVolume() {
        setVolume(currentVolume + 1)
    }

    fun decreaseVolume() {
        setVolume(currentVolume - 1)
    }
}
